import Vue from "vue"
import VueRouter from 'vue-router'
import routes from './routes'
// import NotFound from '@/views/NotFound'

Vue.use(VueRouter)

//重写 push | replace
//先把原型封装保存
let originPush = VueRouter.prototype.push
let originReplace = VueRouter.prototype.replace


//重写方法
VueRouter.prototype.push = function (location, resolve, reject) {
  if(resolve && reject) {
    // call || apply 区别
    // 相同点： 都可以调用函数一次，都可以篡改函数上下文一次
    // 不同点： call传递参数用逗号隔开；apply传递参数以数组传递
    originPush.call(this, location, resolve, reject)
  }else {
    originPush.call(this, location, () => {}, () => {})
  }
}
VueRouter.prototype.replace = function (location, resolve, reject) {
  if(resolve && reject) {
    originReplace.call(this, location, resolve, reject)
  }else {
    originReplace.call(this, location, () => {}, () => {})
  }
}

export default new VueRouter({
  routes,
  // 滚动条滚动行为
  scrollBehavior() {
    // 返回的值代表滚动条在最上方
   return { y:0}
  }
})